
package com.dw.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;

import com.dw.dao.TestDao;
import com.dw.entity.Test;
import com.dw.utils.HibernateSessionFactory;

@Repository
public class ITestDao implements TestDao{

	@Override
	public void addTest(Test test) {
		Session session = HibernateSessionFactory.getSession();

		Transaction tran = session.beginTransaction();
		session.save(test);
		tran.commit();
		HibernateSessionFactory.closeSession(session);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Test> list() {
		Session session = HibernateSessionFactory.getSession();
		List<Test> list = new ArrayList<Test>();
		Transaction tran = session.beginTransaction();
		String hql = "from Test";
		Query query = session.createQuery(hql);
		list = query.list();
		tran.commit();
		HibernateSessionFactory.closeSession(session);
		return list;
	}

}
